package com.bdi.mqtt_broker.mqtt_protocol;

import com.bdi.mqtt_broker.config.BrokerConfig;
import com.bdi.mqtt_broker.service.ChannelManagerService;
import com.bdi.mqtt_broker.service.ISessionStoreService;
import com.bdi.mqtt_broker.service.ISubscribeStoreService;
import io.netty.channel.group.ChannelGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.security.auth.Subject;

/**
 * @author WangNing yogehaoren@gmial.com <br>
 * @since 1.0
 * 协议主处理器
 */
@Component
public class ProtocolProcess {

    @Autowired
    BrokerConfig brokerConfig;

    @Autowired
    ISubscribeStoreService subscribeStoreService;

    @Autowired
    ChannelManagerService channelManagerService;

    @Autowired
    ISessionStoreService sessionStoreService;

    @Autowired
    ChannelGroup channelGroup;

    private Connect connect;

    private DisConnect disConnect;

    private PingReq pingReq;

    private Subscribe subscribe;

    private UnSubscribe unSubscribe;

    private Publish publish;

    public Connect connect(){
        if (connect == null) {
            connect = new Connect(brokerConfig, subscribeStoreService,sessionStoreService, channelGroup, channelManagerService);
        }
        return connect;
    }

    public PingReq pingReq(){
        if(pingReq==null){
            pingReq = new PingReq(sessionStoreService, brokerConfig, channelManagerService);
        }
        return pingReq;
    }

    public Subscribe subscribe(){
        if(subscribe==null){
            subscribe = new Subscribe(subscribeStoreService);
        }
        return subscribe;
    }

    public UnSubscribe unSubscribe(){
        if(unSubscribe == null){
            unSubscribe = new UnSubscribe(subscribeStoreService);
        }
        return unSubscribe;
    }

    public DisConnect disConnect(){
        if(disConnect == null){
            disConnect = new DisConnect(sessionStoreService, subscribeStoreService);
        }
        return disConnect;
    }

    public Publish publish(){
        if(publish == null){
            publish = new Publish(sessionStoreService, subscribeStoreService, channelGroup, channelManagerService);
        }
        return publish;
    }




}
